package com.bbg.amyam.web.mvc.security;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.bbg.amyam.domain.model.Profile;
import com.bbg.amyam.web.util.RequestPathParameter;

public class AmyamUserDetail implements UserDetails, Serializable  {

	private boolean accountNonExpired = true;
	private boolean accountNonLocked = true;
	private Collection<GrantedAuthority> authorities;
	private boolean credentialsNonExpired = true;
	private boolean enabled = true;
	private String password;
	private String username;
	private String fullName;
	
	public AmyamUserDetail(Profile profile, String schoolShortName) {
		this.username=profile.getEmail();
		this.password=profile.getPassword();
		if(StringUtils.isBlank(this.password)){
			this.password="not set yet --- anything";
		}
		this.fullName=profile.getFirstName()+" "+profile.getLastName();
		authorities=UserRoleResolver.listUserRoles(this.username,schoolShortName);
	}
	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}
	public void setAccountNonExpired(boolean accountNonExpired) {
		this.accountNonExpired = accountNonExpired;
	}
	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}
	public void setAccountNonLocked(boolean accountNonLocked) {
		this.accountNonLocked = accountNonLocked;
	}
	public Collection<GrantedAuthority> getAuthorities() {
		return authorities;
	}
	public void setAuthorities(Collection<GrantedAuthority> authorities) {
		this.authorities = authorities;
	}
	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}
	public void setCredentialsNonExpired(boolean credentialsNonExpired) {
		this.credentialsNonExpired = credentialsNonExpired;
	}
	public boolean isEnabled() {
		return enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}

	public String getFullName(){
		return this.fullName;
	}
}
